﻿using Nop.Core.Domain.Logistics;
using System;
using System.Collections.Generic;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Nop.Data.Mapping.Logistics
{
    public class PackageMap : EntityTypeConfiguration<LogisticsPackage>
    {
        public PackageMap()
        {
            this.ToTable("LogisticsPackage");

            this.Property(p => p.CreatedOnUtc).IsRequired();
            this.Property(p => p.UpdatedOnUtc).IsOptional();
            this.Property(p => p.Status).IsRequired();
            this.Property(p => p.OrderKindId).IsRequired();

            this.HasRequired(p => p.Shipment)
                .WithMany()
                .HasForeignKey(p => p.ShipmentId)
                .WillCascadeOnDelete(false);

            this.HasOptional(p => p.Warehouse)
                .WithMany()
                .HasForeignKey(p => p.WarehouseId)
                .WillCascadeOnDelete(false);

            this.HasOptional(p => p.ToWarehouse)
                .WithMany()
                .HasForeignKey(p => p.ToWarehouseId)
                .WillCascadeOnDelete(false);

            this.HasRequired(p => p.PickUpLocation)
                .WithMany()
                .HasForeignKey(p => p.PickUpLocationId)
                .WillCascadeOnDelete(false);

            this.HasRequired(p => p.DeliveryLocation)
                .WithMany()
                .HasForeignKey(p => p.DeliveryLocationId)
                .WillCascadeOnDelete(false);

            this.HasMany(p => p.PackageNotes)
                .WithRequired(pn => pn.Package)
                .WillCascadeOnDelete(false);
        }
    }
}
